<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>pay</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  </head>
  <style>
  </style>
  <body>
    <h1>支付测试</h1>

    <div>
      <label for="appID">appID:</label>
      <input id="appID" name="appID" type="text" value="P806DACB0A00C5D4B3B330FFDDB2B68A4">
    </div>
    <div>
      <label for="openKey">openKey:</label>
      <input id="openKey" name="openKey" type="text" value="0845e708997ee18d11c5fb20d0a142c1">
    </div>
    <div>
      <label for="openid">openid(选填):</label>
      <input id="openid" name="openid" type="text" value="oanZexEwiqzI9akd-lbxaVgt_pt8" placeholder="请填入OpenID">
    </div>
    <div>
      <label for="userName">userName:</label>
      <input id="userName" name="userName" type="text" value="admin@dataeye.com">
    </div>
    <div>
      <label for="productNo">productNo:</label>
      <input id="productNo" name="productNo" type="text" value="P000040">
    </div>
    <div>
      <label for="amount">amount(金额分):</label>
      <input id="amount" name="amount" type="text" value=10>
    </div>
    <div>
      <label for="returnurl">returnurl:</label>
      <input id="returnurl" name="returnurl" type="text" value="http://nba.qq.com">
    </div>
  </div>
    <button onclick="paysome()" style="width: 200px; height: 50px;">支付</button>
    <script src="zepto.min.js"></script>
    <script src="paysdk.min.js?v=1732"></script>
    <script>
		var url = window.location.href.split('?');
		var param = {};
		if (url.length == 2) {
			var tmp = url[1].split('&');
			for (var a in tmp) {
				var tmp2 = tmp[a].split('=');
				if (tmp2.length == 2) {
					param[tmp2[0]] = tmp2[1];
				}
			}
		}
		if (typeof param.openid != 'undefined') {
			$('#openid').val(param.openid);
		} else {
			$('#openid').val('');
		}
      // appID 和 openKey 由优点支付管理后台获取
        var appID = $('#appID').val()
        var openKey = $('#openKey').val()
        var openid = $('#openid').val()
        // 加载页面需要先初始化支付
        // 'W'微信公众号， 'Q' QQ公众号（暂不支持）
        var paysdk = new Paysdk(appID, openKey, 'W', openid)
        paysdk.url = 'https://pay.szwzpay.com'
        paysdk.initPaysdk()
        function paysome() {
          paysdk.openid = $('#openid').val()
          var timestamp = Date.parse(new Date()) + Math.floor(Math.random()*100)
          // orderNo 订单号不可重复
          // userName 用户名
          // productNo 管理后台产品编号
          // amount （分），管理后台设置应用传入价格必须设定amount，平台设定价格可不填，若填amount时，会覆盖平台设定的价格
          // returnurl 支付完成的回调地址
          var orderParams = {
            orderNo: timestamp,
            userName: $('#userName').val(),
            productNo: $('#productNo').val(),
            amount: $('#amount').val(),
            returnurl: $('#returnurl').val(),
          }
          paysdk.pay(orderParams)
        }
    </script>
  </body>
</html>